package client.game.world.map;

import java.awt.Color;
import java.awt.Graphics;

public class Region {

	private int x, y;
	private Tile[][] tiles;
	public PathFinding pathFinding;

	public Region(int x, int y) {
		tiles = new Tile[WorldMap.REGION_SIZE][WorldMap.REGION_SIZE];
	}
	
	public void generateRandom() {
		for(int x = 0; x < tiles.length; x++) {
			for(int y = 0; y < tiles[x].length; y++) {
				Tile t = new Tile(this, x, y);
				tiles[x][y] = t;
				t.getProperties().setBlocked((Math.random() > 0.7));
			}
		}
		this.pathFinding = new PathFinding(this);
	}
	
	public void drawRegion(Graphics g) {
		for(int x = 0; x < tiles.length; x++) {
			for(int y = 0; y < tiles[x].length; y++) {
				g.setColor(tiles[x][y].highlighted ? Color.green : (tiles[x][y].getProperties().blocked() ? Color.red : Color.blue));
				g.fillRect(x*32, y*32, 32, 32);
			}
		}
	}
	
	public Tile getTile(int x, int y) {
		try {
			return tiles[x][y];
		} catch(Exception e) {
			return null;
		}
	}
	
	public int getX() {
		return x;
	}
	
	public int getY() {
		return y;
	}
	
}
